// pages/homework/published_homework/published_detail/answer/answer.js
import Toast from "../../../../../dist/toast/toast"

Page({

  /**
   * 页面的初始数据
   */
  data: {
    status:'',
    value:1,
    id:'',
    homework:'',
    content:''
  },
  submit(e){
    let _this=this;
    _this.setData({
      content:e.detail.value.content
    })
    console.log(wx.getStorageSync('openId'));
    
    wx.request({
      url: 'https://www.yunmosf.top/job/question/answer',
      method:'POST',
      data:{
        openid:wx.getStorageSync('openId'),
        comment:_this.data.content,
        score:_this.data.value,
        answer_id:_this.data.id
      },
      header: {
       'Content-Type': 'application/x-www-form-urlencoded'
     },
      success(res){
          _this.setData({
            'homework.comment':_this.data.content,
            'homework.score':_this.data.value,
            status:1
          })
          Toast.success('批改成功');
      
      }
    })
  },

  onChange(event) {
    this.setData({
      value: event.detail,
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let _this=this;
    let id=options.id;
    _this,this.setData({
      id:id
    })

    wx.request({
      url: 'https://www.yunmosf.top/job/answer',
      method:'GET',
      data:{
        openid:wx.getStorageSync('openId'),
        answer_id:_this.data.id,
        type:0
      },
      success(res){
        let data=JSON.parse(res.data.data); 
        if(data.score==null){
          _this.setData({
            status:0
          })
        }
        else
        {
          _this.setData({
            status:1
          })
        }
        
        _this.setData({
          homework:data
        })
        console.log(res);
        
      }
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})